package com.framework.Module.system.company;


import com.framerock.baselib.CDate;
import com.framerock.baselib.CLog;
import com.framerock.baselib.Json;
import com.framerock.baselib.Rock;
import com.framework.ACore.ModuleFields;
import com.framework.ACore.ModuleInfo;
import com.framework.Table.Table;


public class Tablecompany extends Table {


    protected void initTable() {
        this.tablename   = "company";
        this.tablenamesm = "单位管理";

        this.flowsetMap  = Rock.getMap(new String[]{
                "type", "系统",
                "sort", "907",
                "isxt", "1",
        });

        //设置模块信息说明要添加模块里面
        this.setModuleInfo(ModuleInfo.get()
                .setType("系统")
                .setSort(907)
                .setIsxt(1));

        this.addModuleFields(ModuleFields.get()
                .setName("单位Logo")
                .setFields("logo")
                .setType("varchar(200)")
                .setIsss(ModuleFields.CLOSE)
                .setFieldstype("uploadimg")
        );

        this.addModuleFields(ModuleFields.get()
                .setName("单位名称")
                .setFields("name")
                .setType("varchar(50)")
                .setIsalign(ModuleFields.ALIGN_LEFT)
                .setIsss(ModuleFields.OPEN)
                .setIsbt(ModuleFields.OPEN)
        );

        this.addModuleFields(ModuleFields.get().setName("单位简称").setFields("nameshort").setType("varchar(50)").setIsss(ModuleFields.OPEN).setIsalign(ModuleFields.ALIGN_CENTER));

        this.addModuleFields(ModuleFields.get().setName("编号").setFields("num").setType("varchar(50)").setIsss(1).setIsonly(1).setAttr("onlyen").setIsbt(1));

        this.addModuleFields(ModuleFields.get().setName("状态").setFields("status").setType("tinyint(1)").setIspx(1).setFieldstype("checkbox").setPlaceholder("启用单位").setDev("1").setData("0|停用|gray,1|启用|green"));


        this.addfields("sort", "int(11)", "0", "排序号",new String[]{
                "iseditlx","1",
                "ispx","1"
        });
        this.addfields("adddt", "datetime", null, "添加时间",new String[]{
                "islu","0"
        });
        this.addfields("uid", "int(11)", "0", "创建人ID",new String[]{
                "islu","0"
        });
        this.addfields("hmode", "tinyint(1)", "0", "主页模式@0|菜单形式,1|IM形式,2|桌面形式",new String[]{
                "islu","1",
        });
        this.addfields("id", "int(11)", "0", "ID");
        this.addfields("num", "UNIQUE KEY", "`num`", "编号索引");
    }

    //创建默认第一个单位
    protected void firstInsert() {
        int count = this.nDb.getCount(this.tablenameal, "`id`=1");
        if(count==0) {
            this.nDb.insert(this.tablenameal, Rock.getMap(new String[]{
                    "id", "1",
                    "uid", "1",
                    "num", "xinhu",
                    "logo", "http://www.rockoa.com/images/logo.png",
                    "name", "信呼Java开发团队",
                    "adddt", CDate.now(),
            }));
        }
    }
}
